class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        # 判断边界值，不存在直接返回
        if len(nums) == 0 or target < nums[0] or target > nums[-1]:
            return [-1, -1]

        res = []
        # 寻找左边界
        def find_left_bound(nums, target):
            l, r = 0, len(nums)-1
            while l <= r:
                middle = (l + r) // 2
                if nums[middle] >= target:
                    r = middle - 1
                else:
                    l = middle + 1

            if l > len(nums)-1 or nums[l] != target:
                res.append(-1)
            else:
                res.append(l)

        # 寻找右边界
        def find_right_bound(nums, target):
            l, r = 0, len(nums)-1
            while l <= r:
                middle = (l + r) // 2
                if nums[middle] <= target:
                    l = middle + 1
                else:
                    r = middle - 1

            if r < 0 or nums[r] != target:
                res.append(-1)
            else:
                res.append(r)

        find_left_bound(nums, target)
        # 没有左边界直接返回
        if res[0] == -1:
            res.append(-1)
            return res
        find_right_bound(nums, target)

        return res

                
                



        